//
//  DataController.m
//  SHWT
//
//  Created by Rui on 14/10/23.
//  Copyright (c) 2014年 xingheng. All rights reserved.
//

#import "DataController.h"

@implementation DataController

/**
 *  用户登陆
 *
 *  @param telNum    手机号/用户名
 *  @param password  登录密码
 *  @param loginType 登录类型
 *  @param imei      设备号
 *  @param success   成功回调
 */
+ (void)userLogin:(NSString *)telNum
         password:(NSString *)password
        loginType:(NSString *)loginType
             imei:(NSString *)imei
        withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     telNum,@"telNum",
                                     password,@"password",
                                     loginType,@"loginType",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/user/userLogin"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];
}

/**
 *  重置密码
 *
 *  @param loginName        登录账号
 *  @param telNum           手机号/用户名
 *  @param verificationCode 验证码
 *  @param newPassword      新密码
 *  @param userType         用户类型
 *  @param success          成功回调
 */
+ (void)resetPassword:(NSString *)loginName
               telNum:(NSString *)telNum
     verificationCode:(NSString *)verificationCode
          newPassword:(NSString *)newPassword
             userType:(NSString *)userType
            withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     loginName,@"loginName",
                                     telNum,@"telNum",
                                     verificationCode,@"verificationCode",
                                     newPassword,@"newPassword",
                                     userType,@"userType", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/user/resetPassword"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];
}

/**
 *  用户注册
 *
 *  @param loginName        登录名
 *  @param password         登录密码
 *  @param loginType        登录类型
 *  @param userName         联系人
 *  @param telNum           手机号码
 *  @param verificationCode 验证码
 *  @param success          成功回调
 */
+ (void)userRegist:(NSString *)loginName
          password:(NSString *)password
         loginType:(NSString *)loginType
          userName:(NSString *)userName
            telNum:(NSString *)telNum
  verificationCode:(NSString *)verificationCode
         withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     loginName,@"loginName",
                                      password,@"password",
                                     loginType,@"loginType",
                                      userName,@"userName",
                                        telNum,@"telNum",
                              verificationCode,@"verificationCode", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/user/userRegist"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];

}

/**
 *  文件上传
 *
 *  @param userId  用户id
 *  @param imei    设备号
 *  @param success 成功回调
 */
+ (void)singleFileUpload :(NSNumber *)userId
                     imei:(NSString *)imei
                withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     userId,@"userId",
                                     imei,@"imei",
                                     nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/public/singleFileUpload"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];
}

+ (void)textRequest:(NSNumber *)orgId
             userId:(NSNumber *)userId
             lastId:(NSNumber *)lastId
               imei:(NSString *)imei
          withBlock:(void (^)(NSDictionary *))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orgId,@"orgId",
                                     userId,@"userId",
                                     lastId,@"lastId",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/goods/getPushGoods"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
}

/**
 *  获取共享货源列表信息
 *
 *  @param orgId   orgId description
 *  @param userId  userId description
 *  @param lastId  lastId description
 *  @param imei    imei description
 *  @param success 成功回调
 */
+ (void)getShareGoods:(NSNumber *)orgId
               userId:(NSNumber *)userId
               lastId:(NSNumber *)lastId
                 imei:(NSString *)imei
            withBlock:(void(^)(NSDictionary *result))success{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orgId,@"orgId",
                                     userId,@"userId",
                                     lastId,@"lastId",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/goods/getShareGoods"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         //         NSLog(@"JSON: %@ ===%@  === %@", responseObject, [responseObject objectForKey:@"resMsg"], [[responseObject objectForKey:@"resMsg"] class]);
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
}


/**
 *  获取当前货单列表信息
 *
 *  @param orgId    orgId
 *  @param userId   userId
 *  @param lastId   lastId
 *  @param userType userType
 *  @param imei     imei
 *  @param success  成功回调
 */
+ (void)getCurOrder:(NSNumber *)orgId
             userId:(NSNumber *)userId
             lastId:(NSNumber *)lastId
           userType:(NSString *)userType
               imei:(NSString *)imei
          withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                      orgId,@"orgId",
                                     userId,@"userId",
                                     lastId,@"lastId",
                                   userType,@"userType",
                                       imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getCurOrder"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
         NSLog(@"Error: %@", error);
     }];

}

/**
 *  获取历史货单列表信息
 *
 *  @param orgId    orgId
 *  @param userId   userId
 *  @param lastId   lastId
 *  @param userType userType
 *  @param imei     imei
 *  @param success  成功回调
 */
+ (void)getHisOrder:(NSNumber *)orgId
             userId:(NSNumber *)userId
             lastId:(NSNumber *)lastId
           userType:(NSString *)userType
               imei:(NSString *)imei
          withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orgId,@"orgId",
                                     userId,@"userId",
                                     lastId,@"lastId",
                                     userType,@"userType",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getHisOrder"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}


/**
 *  获取货单详细信息
 *
 *  @param orgId    orgId
 *  @param userId   userId
 *  @param userType userType
 *  @param imei     imei
 *  @param success  成功回调
 */
+ (void)getOrderDetail:(NSNumber *)orderId
                userId:(NSNumber *)userId
              userType:(NSString *)userType
                  imei:(NSString *)imei
             withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orderId,@"orderId",
                                      userId,@"userId",
                                    userType,@"userType",
                                        imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getOrderDetail"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

/**
 *  获取物流商公司所有车牌号信息
 *
 *  @param orgId    orgId
 *  @param userId   userId
 *  @param imei     imei
 *  @param success  成功回调
 */
+ (void)getLicensePlate:(NSNumber *)orgId
                 userId:(NSNumber *)userId
                   imei:(NSString *)imei
              withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orgId,@"orgId",
                                     userId,@"userId",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/truck/getLicensePlate"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

/**
 *  选择车辆页面选择完成
 *
 *  @param goodsId 货物id
 *  @param orgId   物流商id
 *  @param orderId 订单id
 *  @param userId  用户id
 *  @param truckId 车辆id
 *  @param type    操作类型
 *  @param note    备注
 *  @param imei    设备号
 *  @param success 成功返回
 */
+ (void)changeOrderStatus:(NSNumber *)goodsId
                    orgId:(NSNumber *)orgId
                  orderId:(NSNumber *)orderId
                   userId:(NSNumber *)userId
                  truckId:(NSString *)truckId
                     type:(NSString *)type
                     note:(NSString *)note
                     imei:(NSString *)imei
                withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     goodsId,@"goodsId",
                                       orgId,@"orgId",
                                     orderId,@"orderId",
                                      userId,@"userId",
                                     truckId,@"truckId",
                                        type,@"type",
                                        note,@"note",
                                        imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/changeOrderStatus"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

/**
 *  获取货车信息
 *
 *  @param truckId      车辆id
 *  @param userId       用户id
 *  @param licensePlate 车辆id
 *  @param imei         设备号
 *  @param success      成功回调
 */
+ (void)getTruckDetail:(NSNumber *)truckId
                userId:(NSNumber *)userId
          licensePlate:(NSString *)licensePlate
                  imei:(NSString *)imei
             withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     
                                     truckId,@"truckId",
                                      userId,@"userId",
                                licensePlate,@"licensePlate",
                                        imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/truck/getTruckDetail"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

@end




